import greenfoot.Actor;
import java.awt.Color;

import lejos.nxt.SensorPort;
import lejos.nxt.UltrasonicSensor;
import greenfoot.GreenfootImage;
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class LegoUltraSnd here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LegoUltraSnd extends Actor {
	private UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S4);
	private GreenfootImage image_text = new GreenfootImage(
			"images/legoUltras.png");

	/**
	 * constructor
	 */
	public LegoUltraSnd() {
		// put your code here
		setImage(image_text);

	}

	/**
	 * Act - do whatever the LegoUltraSnd wants to do. This method is called whenever
	 * the 'Act' or 'Run' button gets pressed in the environment.
	 */
	public void act() {
		// Add your action code here.
		image_text.setColor(Color.WHITE);
		image_text.fillRect(2, 30, 20, 20); //erase part of image for new text
		image_text.setColor(Color.BLACK);
		image_text.drawString(Integer.toString(sonic.getDistance()), 2, 40);
		//System.out.println("distance = " + sonic.getDistance());
	}
}
